package com.zhang.stack;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * @author zhang
 * @time 2022/03/07 20:49:26
 */
public class StackWithTwoQueue {
    Queue<Integer> queue1 = new ArrayDeque<>();
    Queue<Integer> queue2 = new ArrayDeque<>();
    private int top;

    public void push(Integer item) {
        queue1.add(item);

    }
    public Integer pop() {

       while (queue1.size() > 1) {
           top = queue1.remove();
           queue2.add(top);
       }

        swapQueues();

        return queue2.remove();

    }
    private void swapQueues() {
        Queue<Integer> temp = queue1;
        queue1 = queue2;
        queue2 = temp;
    }

    public static void main(String[] args) {
        StackWithTwoQueue stack = new StackWithTwoQueue();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        System.out.println(stack.pop());
    }
}
